package net.dgg.dggcloud.service.jrcrm.service.mq;

import java.io.IOException;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Envelope;

import net.dgg.dggcloud.service.iboss.constant.SysRecordConstant;
import net.dgg.dggcloud.service.jrcrm.service.log.SysRecordService;
import net.dgg.framework.tac.mq.rabbitmq.queue.normal.DggAbstractNormalConsumer;
import net.dgg.framework.tac.spring.context.DggSpringContext;

/**
 * 内控中心日志
 * 
 * @Title: SysRecordConsumer
 * @Description:
 * @Auther: 雷力
 * @Date: 2018-11-19 10:50:41
 *
 */
public class SysRecordConsumer extends DggAbstractNormalConsumer<String> {
	private static final Logger logger = LoggerFactory.getLogger(SysRecordConsumer.class);

	public SysRecordConsumer() {
		this.queueName = SysRecordConstant.QUEUENAME;
		this.hasDeadQueue = false;
		this.qosNum = 200;
	}

	public void setExchangeName(String exchangeName) {
		this.exchangeName = exchangeName;
	}

	/**
	 * 内控中心日志保存
	 * 
	 * @param s
	 * @param envelope
	 * @param basicProperties
	 * @param sysOperateLog
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	@Override
	protected void handleDelivery(String s, Envelope envelope, AMQP.BasicProperties basicProperties, String str) throws IOException {
		logger.info("======================>接收消息...");
		try {
			Map<String, Object> map = JSON.parseObject(str, Map.class);
			SysRecordService sysRecordService = (SysRecordService) DggSpringContext.getBean(Class.forName(map.get("clazz").toString()));
			logger.error(map.get("clazz").toString());
			sysRecordService.insert(map);
		} catch (Exception e) {
			logger.error("内控中心日志保存异常：", e);
		}
	}
}
